package com.qf.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.pojo.DtsUser;
import com.qf.vo.DayStatis;
import com.qf.vo.UserRowsVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author zhaojian
 * @since 2021-05-12
 */
public interface DtsUserMapper extends BaseMapper<DtsUser> {

    /**
     * 统计用户按天的增长量
     * @return
     */
    @Select("select DATE_FORMAT(add_time,\"%Y-%m-%d\") as dayStr, count(*) as cnts " +
            "from dts_user " +
            "where deleted = 0 and add_time > DATE_ADD(now(),INTERVAL - #{daysAgo} day) " +
            "GROUP BY DATE_FORMAT(add_time,\"%Y-%m-%d\") ")
    public List<DayStatis> statisIncrCnt(@Param("daysAgo") Integer daysAgo);

    @Select("select DATE_FORMAT(add_time,\"%Y-%m-%d\") as day, count(*) as users\n" +
            "from dts_user \n" +
            "GROUP BY DATE_FORMAT(add_time,\"%Y-%m-%d\") ")
    public List<UserRowsVo> statisUsers();
}
